package com.wechatpay.v3.sdk.data;

import java.io.Serializable;

/**
 * 微信支付请求数据封装
 *
 * 优惠功能、支付场景描述、结算信息未实现
 * @author liuyi <liuy@pvc123.com>
 * @since 2021/7/30
 */
public class WechatPayRequestData implements Serializable {

    //************** 必填项目 *****************
    /** 请求基础下单接口时的应用APPID，如公众号id，小程序id，app应用Id等，可根据用户场景自行传入 */
    private String appid;
    /** 直连商户的商户号，由微信支付生成并下发，只限于配置文件配置，不可代码传入 */
    private String mchid;
    /** 商品描述 */
    private String description;
    /** 商户系统内部订单号，只能是数字、大小写字母_-，在同一个商户号下唯一 */
    private String out_trade_no;
    /** 通知URL必须为直接可访问的URL，不允许携带查询串，要求必须为https地址 */
    private String notify_url;

    private Amount amount;

    private Payer payer;
    //************** 非必填项目 *****************
    /** 订单失效时间，遵循rfc3339标准格式，格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE，如 2015-05-20T13:29:35+08:00 */
    //private String time_expire;
    /** 附加数据，在查询API和支付通知中原样返回，可作为自定义参数使用 */
    private String attach;

    public WechatPayRequestData(String appid, String mchid, String description, String out_trade_no, String notify_url, int amount, String openId) {
        this.appid = appid;
        this.mchid = mchid;
        this.description = description;
        this.out_trade_no = out_trade_no;
        this.notify_url = notify_url;
        this.amount = new Amount(amount);
        this.payer = new Payer(openId);
        this.attach = "未填写自定义字段";
        //this.time_expire = new Date().toString();
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getMchid() {
        return mchid;
    }

    public void setMchid(String mchid) {
        this.mchid = mchid;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
    }

    public Amount getAmount() {
        return amount;
    }

    public void setAmount(Amount amount) {
        this.amount = amount;
    }

    public Payer getPayer() {
        return payer;
    }

    public void setPayer(Payer payer) {
        this.payer = payer;
    }

    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }

    public static class Amount {
        /** 订单总金额，单位为分 */
        private int total;
        /** CNY：人民币，境内商户号仅支持人民币 */
        private String currency;

        public Amount(){}

        public Amount(int total) {
            this.total = total;
            this.currency = "CNY";
        }

        public int getTotal() {
            return total;
        }

        public void setTotal(int total) {
            this.total = total;
        }

        public String getCurrency() {
            return currency;
        }

        public void setCurrency(String currency) {
            this.currency = currency;
        }
    }

    static class Payer {
        private String openid;

        public Payer(){}

        public Payer(String openid) {
            this.openid = openid;
        }

        public String getOpenid() {
            return openid;
        }

        public void setOpenid(String openid) {
            this.openid = openid;
        }
    }
}
